
package com.anuo.app.common.globalhandle;

import com.anuo.app.common.utils.PropertiesUtil;
import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.ServletContext;
import java.nio.charset.Charset;
import java.util.Date;
import java.util.Map;

/**
 * 全局配置类
 */
public class GlobalConfig {

    /**
     * 属性文件加载对象
     */
    private static PropertiesUtil loader = new PropertiesUtil("anuoapp.properties");


    /**
     * 缓存全局属性值 (避免频繁从文件中读取属性值)
     */
    private static Map<String, String> map = Maps.newHashMap();

    public static boolean inMaintenance;
    public static Date maintenanceBeginTime;
    public static Date maintenanceEndTime;
    /**
     * 静态化UTF_8 Charset 对象 避免频繁查找消耗
     */
    public static final Charset UTF_8 = Charset.forName("UTF-8");

    /**
     * 获取配置, 并缓存到map
     */
    public static String getConfig(String key) {
        String value = map.get(key);
        if (value == null) {
            value = loader.getProperty(key);
            map.put(key, value != null ? value : "");
        }
        return value;
    }



}
